home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE08 / CONSTRUC / COMPMENU.PAS next >
Encoding:
Pascal/Delphi Source File  |  1996-02-20  |  3.3 KB  |  106 lines

  1. unit CompMenu;
  2. interface
  3. uses
  4.   DsgnIntf;
  5.  
  6. Type
  7.   TCommonDialogComponentEditor = class(TComponentEditor)
  8.     function GetVerbCount: Integer; override;
  9.     function GetVerb(index: Integer): String; override;
  10.     procedure Executeverb(index: Integer); override;
  11.   end;
  12.  
  13.   TCommonDialogDefaultEditor = class(TDefaultEditor)
  14.     function GetVerbCount: Integer; override;
  15.     function GetVerb(index: Integer): String; override;
  16.     procedure Executeverb(index: Integer); override;
  17.   end;
  18.  
  19.   procedure Register;
  20.  
  21. implementation
  22. uses
  23.   Dialogs;
  24.  
  25.   { TCommonDialogComponentEditor }
  26.  
  27.   function TCommonDialogComponentEditor.GetVerbCount: Integer;
  28.   begin
  29.     GetVerbCount := 2
  30.   end {GetVerbCount};
  31.  
  32.   function TCommonDialogComponentEditor.GetVerb(index : Integer): String;
  33.   begin
  34.     if Index >= 1 then GetVerb := '&About...'
  35.                   else GetVerb := '&Execute ' + Component.ClassName + '...'
  36.   end {GetVerb};
  37.  
  38.   procedure TCommonDialogComponentEditor.ExecuteVerb(index: Integer);
  39.   begin
  40.     if index >= 1 then
  41.       MessageDlg('TCommonDialogComponentEditor (c) 1996 by Dr.Bob#13for The Delphi Magazine',
  42.                   mtInformation, [mbOk], 0)
  43.     else
  44.     begin
  45.       if (Component IS TOpenDialog) then { also TSaveDialog }
  46.         (Component AS TOpenDialog).Execute
  47.       else
  48.         if (Component IS TPrintDialog) then
  49.           (Component AS TPrintDialog).Execute
  50.         else
  51.           if (Component IS TPrinterSetupDialog) then
  52.             (Component AS TPrinterSetupDialog).Execute
  53.           else
  54.             if (Component IS TColorDialog) then
  55.               (Component AS TColorDialog).Execute;
  56.       Designer.Modified
  57.     end
  58.   end {ExecuteVerb};
  59.  
  60.   { TCommonDialogDefaultEditor }
  61.  
  62.   function TCommonDialogDefaultEditor.GetVerbCount: Integer;
  63.   begin
  64.     GetVerbCount := 3
  65.   end {GetVerbCount};
  66.  
  67.   function TCommonDialogDefaultEditor.GetVerb(index : Integer): String;
  68.   begin
  69.     case Index of
  70.       0: GetVerb := '&OnEvent handler code';
  71.       1: GetVerb := '&Execute ' + Component.ClassName + '...';
  72.       else GetVerb := '&About...'
  73.     end
  74.   end {GetVerb};
  75.  
  76.   procedure TCommonDialogDefaultEditor.ExecuteVerb(index: Integer);
  77.   begin
  78.     if index >= 2 then
  79.       MessageDlg('TCommonDialogDefaultEditor (c) 1996 by Dr.Bob#13for The Delphi Magazine',
  80.                   mtInformation, [mbOk], 0)
  81.     else
  82.     if index = 1 then
  83.     begin
  84.       if (Component IS TFindDialog) then { also TReplaceDialog }
  85.         (Component AS TFindDialog).Execute
  86.       else
  87.         if (Component IS TFontDialog) then
  88.           (Component AS TFontDialog).Execute;
  89.       Designer.Modified
  90.     end
  91.     else inherited Edit { TDefaultEditor.Edit }
  92.   end {ExecuteVerb};
  93.  
  94.   procedure Register;
  95.   begin
  96.     { empty default component editors }
  97.     RegisterComponentEditor(TOpenDialog, TCommonDialogComponentEditor);
  98.     RegisterComponentEditor(TPrintDialog, TCommonDialogComponentEditor);
  99.     RegisterComponentEditor(TPrinterSetupDialog, TCommonDialogComponentEditor);
  100.     RegisterComponentEditor(TColorDialog, TCommonDialogComponentEditor);
  101.     { event default component editors }
  102.     RegisterComponentEditor(TFontDialog, TCommonDialogDefaultEditor);
  103.     RegisterComponentEditor(TFindDialog, TCommonDialogDefaultEditor)
  104.   end;
  105. end.
  106.